<%@ page import="java.io.*, java.text.*, java.util.Date, java.sql.*, javax.servlet.*, javax.servlet.http.*, java.util.*" %>
<%
String usernameSC = (String) session.getAttribute("session_name");
String idSC = (String) session.getAttribute("id");
String typeSC = (String) session.getAttribute("type");
if(usernameSC != null && !(typeSC.equals("student"))) {
	String driver ="com.mysql.jdbc.Driver";
	String url = "jdbc:mysql://localhost:3306/projects";
	String username = "ia";
	String password = "123";
	String name;
	String [] col = new String[10];
	String [] data = new String[10];
	String fontStyle = "";
	String fontSize = "";
	String[] events = new String[4];
	int index= 0;
	SimpleDateFormat time = new SimpleDateFormat("hh:mm:ss a");
	SimpleDateFormat day = new SimpleDateFormat("MM/dd/yyyy");
	events[2]= day.format(new Date());
	events[3]= time.format(new Date());
	
	Enumeration project = request.getParameterNames();


	while(project.hasMoreElements())
	{
		name = (String)project.nextElement();
	
		if(!(name.equals("fColor") || name.equals("fStyle") || name.equals("fSize")))
		{
			col += name+",";
			data += "'"+request.getParameter(name)+"',";
		}
	
	}

	col += "Status,Creation_Date,Last_Modification_Date,professor_id";
	data += "'pend','"+events[2]+" "+events[3]+"','"+events[2]+" "+events[3]+"',"+idSC;
	
	try
	{
		Class.forName(driver).newInstance();
		Connection connection = DriverManager.getConnection(url, username, password);
		Statement statement = connection.createStatement();
		String query="INSERT INTO projects ("+col+") values("+data+")";
		statement.executeUpdate(query);
		connection.close();	
	}catch(ClassNotFoundException cnfe)
	{
		out.println("<br>Couldn't find class file" + cnfe); 
	}catch(SQLException sqle)
	{
		out.println("<br>SQL Exception: " + sqle);
	}catch(InstantiationException ie)
	{
		out.println("<br>Instant exception : " + ie);
	}catch(IllegalAccessException iae)
	{
		out.println("<br>Illegal access exception : " + iae);
	}
	response.sendRedirect("index.jsp");
}
else {
	response.sendRedirect("error.jsp");
}

%>